/*
 * Keyboard.cpp
 *
 * Author: Samuel Queiroz
 */

#include "Keyboard.h"

void Keyboard::run()
{
	switch( event->type )
	{
		case SDL_KEYDOWN:
			switchPressedKey(&event->key.keysym);
			break;
		case SDL_KEYUP:
			switchReleasedKey(&event->key.keysym);
			break;
		default:
			break;
	}
}

void Keyboard::switchPressedKey(SDL_keysym *keysym)
{
	switch( keysym->sym )
	{
		case SDLK_RETURN:
			robotSwitcher.switch_();
			break;
		case SDLK_RSHIFT:
			controlSwitcher.switch_();
			break;
		case SDLK_LEFT:
			(keysym->mod & KMOD_CTRL)
				? rotationSlider->decrement()
				: leftButton.press();
			break;
		case SDLK_RIGHT:
			(keysym->mod & KMOD_CTRL)
				? rotationSlider->increment()
				: rightButton.press();
			break;
		case SDLK_UP:
			(keysym->mod & KMOD_CTRL)
				? speedSlider->increment()
				: upButton.press();
			break;
		case SDLK_DOWN:
			(keysym->mod & KMOD_CTRL)
				? speedSlider->decrement()
				: downButton.press();
			break;
		case SDLK_ESCAPE:
			stopButton.press();
			break;
		default:
			break;
	}
}

void Keyboard::switchReleasedKey(SDL_keysym *keysym)
{
	switch(keysym->sym)
	{
		case SDLK_LEFT:
			leftButton.release();
			break;
		case SDLK_RIGHT:
			rightButton.release();
			break;
		case SDLK_UP:
			upButton.release();
			break;
		case SDLK_DOWN:
			downButton.release();
			break;
		default:
			break;
	}
}
